<?php

namespace App\Http\Controllers\User;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class MovieController extends Controller
{
    //
    public function getHeadMovie(){

        try{
            $result = DB::table('movie')->where('header','=',1)->orderby('movie_id','desc')->take(1)->get();

            return json_encode(['msg'=>1,'data' => $result]);
        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }
    //
    public function getMovie(){

        try{
            $result = DB::table('movie')->where('type','=',1)->orderby('movie_id','desc')->get();

            return json_encode(['msg'=>1,'data' => $result]);
        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }
    public function getTV(){

        try{
            $result = DB::table('movie')->where('type','=',2)->orderby('movie_id','desc')->get();

            return json_encode(['msg'=>1,'data' => $result]);
        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }  
    }
    public function getAd(){

        try{
            $result = DB::table('movie')->where('type','=',4)->orderby('movie_id','desc')->get();

            return json_encode(['msg'=>1,'data' => $result]);
        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }
    public function getShortFilm(){

        try{
            $result = DB::table('movie')->where('type','=',3)->orderby('movie_id','desc')->get();

            return json_encode(['msg'=>1,'data' => $result]);
        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }
}
